
/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __LIST_VIEW_H__
#define __LIST_VIEW_H__

#include <iostream>
#include <components/ui_label_button.h>
#include <components/ui_label.h>
#include <components/ui_checkbox.h>
#include <components/ui_image_view.h>
#include <components/ui_scroll_view.h>
#include <components/ui_surface_view.h>
#include <components/ui_slider.h>
#include <components/ui_view.h>
#include <components/ui_view_group.h>
#include <layout/list_layout.h>
#include <utility>
#include <ability_loader.h>

#include "list.h"

#include "ui_config.h"

using namespace std;

namespace OHOS{

class ListItem {
public:
    ListItem(string image) : bkImage_(image)
    {
        style_ = 0;
    }

    ListItem(string image, int style) : bkImage_(image), style_(style) {}
    ~ListItem();

    void Create(UI_RECT rect);
    void SetItem(const char *image, UI_RECT imageRect, const char *text, UI_RECT textRect, int fontSize);
    void SetOnClick(UIView::OnClickListener *onClick);
    void SetText(const char *text);

    UIView* GetView();
    char* GetText();

    static constexpr int STYLE_VERTICAL = 0;
    static constexpr int STYLE_LEFT_RIGHT = 1;
    static constexpr int STYLE_RIGHT_LEFT = 2;
    static constexpr int STYLE_MAX = 3;
private:
    UIViewGroup *container_ { nullptr };
    UIImageView *background_ { nullptr };
    UIImageView *itemIcon_ { nullptr };
    UILabel *itemText_ { nullptr };

    string bkImage_;
    int style_;
};

class ListView {
public:
    ListView(AbilitySlice *slice, int type, string title) : slice_(slice), fileType_(type), titleName_(title)
    {
        width_ = 0;
        height_ = 0;
    }
    ~ListView();

    void Create(UI_RECT rect, const char *backImage);
    void SetList(List<string> list);
    void Update(List<string> list);
    void Display();
    void Dismiss();

    UIView* GetView();

private:
    UIViewGroup *container_ { nullptr };
    UIImageView *background_ { nullptr };
    UIImageView *backButton_ { nullptr };
    UILabel *title_ { nullptr };

    UIScrollView *scroll_ { nullptr };
    List<string> list_;
    AbilitySlice *slice_ { nullptr };

    int fileType_;
    string titleName_;

    int width_;
    int height_;

    void AddItem(const char *text, int idx);

    static constexpr int LINE_HEIGHT = 72;
    static constexpr int LINE_NBR = 6;
    static constexpr int LINE_POS = 8;

    static constexpr int ICON_START_X = 32;
    static constexpr int ICON_START_Y = 22;
    static constexpr int ICON_WIDTH = 28;
    static constexpr int ICON_HEIGHT = 28;

    static constexpr int TEXT_START_X = 80;
    static constexpr int TEXT_START_Y = 22;

    static constexpr int LISTVIEW_START_X = 16;
    static constexpr int LISTVIEW_START_Y = 0;

    static constexpr int TITLE_WIDTH = 0;
    static constexpr int TITLE_HEIGHT = 92;

    static constexpr int BACK_ICON_XPOS = 24;
    static constexpr int BACK_ICON_YPOS = 24;
    static constexpr int BACK_ICON_WIDTH = 48;
    static constexpr int BACK_ICON_HEIGHT = 48;
};
}

#endif  /* __LIST_VIEW_H__ */
